import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/Login',
      name:"Login",
      component: () => import('@/views/Login.vue')
    },
    {
      path: '/',
      name: 'Main',
      component:()=>import('@/views/Main.vue'),
      children: [
        {
          path: '/Home',
          name: 'Home',
          component: () => import('@/views/Home.vue'),
          meta: {
            title: '首页'
          }
        },
        {
          path: '/Plan',
          name: 'Plan',
          component: () => import('@/views/Plan.vue'),
          meta: {
            title: '组织'
          }
        },
        {
          path: '/Role',
          name: 'Role',
          component: () => import('@/views/Role.vue'),
          meta: {
            title: '角色'
          }
        },
        {
          path: '/Staff',
          name: 'Staff',
          component: () => import('@/views/Staff.vue'),
          meta: {
            title: '员工'
          },
          children: [
            {
              path: '/Staff/Addstaff',
              name: 'Addstaff',
              component: () => import('@/views/Addstaff.vue'),
              meta: {
                title: '添加员工'
              },
            }
          ]
        },
        {
          path: '/Authority',
          name: 'Authority',
          component: () => import('@/views/Authority.vue'),
          meta: {
            title: '权限'
          }
        },
        {
          path: '/Attendance',
          name: 'Attendance',
          component: () => import('@/views/Attendance.vue'),
          meta: {
            title: '考勤'
          }
        },
        {
          path: '/Approval',
          name: 'Approval',
          component: () => import('@/views/Approval.vue'),
          meta: {
            title: '审批'
          }
        },
        {
          path: '/Wages',
          name: 'Wages',
          component: () => import('@/views/Wages.vue'),
          meta: {
            title: '工资'
          }
        },
        {
          path: '/Social',
          name: 'Social',
          component: () => import('@/views/Social.vue'),
          meta: {
            title: '社保'
          },
        },
        {
          path:'/LeaveApplication',
          name:'LeaveApplication',
          component:()=>import('@/views/LeaveApplication.vue'),
          meta:{
            title:'请假申请'
          }
        },
        {
          path:'/Shendetail',
          name:'Shendetail',
          component:()=>import('@/views/Shendetail.vue'),
          meta:{
            title:'审批详情'
          },},

          {
          path: '/SocialList',
          name: 'SocialList',
          component: () => import('@/views/SocialList.vue'),
          meta: {
            title: '社保月份报表'
          }
        },
        {
          path: '/localSocialList',
          name: 'localSocialList',
          component: () => import('@/views/localSocialList.vue'),
          meta: {
            title: '社保历史归档'
          }
        }
      ]
    }]
})

export default router
//  路由守卫
router.beforeEach((to, from, next) => {
 if(to.path === '/Login') return next()
 const tokenStr = window.localStorage.getItem('token')
 if(!tokenStr) return next('/Login')
 next(
  
 )
})